﻿using Architecture.API.Application.TraceabilityCommand.ShoppingCommand;
using MediatR;
using Traceability.Domain.Service.ShoppingServices;

namespace Architecture.API.Application.TraceabilityCommandHandler.ShoppingCommandHandler
{
    /// <summary>
    /// 
    /// </summary>
    public class ShoppingRemoveCommandHandler : IRequestHandler<ShoppingRemoveCommand, int>
    {
        /// <summary>
        /// 商品服务
        /// </summary>
        protected readonly IShoppingService shoppingService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="shoppingService">商品服务</param>
        public ShoppingRemoveCommandHandler(IShoppingService shoppingService)
        {
            this.shoppingService = shoppingService;
        }

        /// <summary>
        /// 删除商品信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(ShoppingRemoveCommand request, CancellationToken cancellationToken)
        {
            return await shoppingService.DeletedShopping(request.shoppingId, request.userName);
        }
    }
}
